package com.example.shop.wx.controller;

import com.example.shop.base.BaseController;
import com.example.shop.base.Result;
import com.example.shop.domain.wx.WxUser;
import com.example.shop.wx.service.WxUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author hcj
 * @date 2018-09-18 22:44:47
 */
@Controller
@RequestMapping(value = "/shop/wxUser")
public class WxUserController extends BaseController {

    @Autowired
    private WxUserService wxUserService;

    @ModelAttribute
    public WxUser get(@RequestParam(required = false) String id) {
        if (StringUtils.isNotBlank(id)) {
            return wxUserService.get(id);
        } else {
            return new WxUser();
        }
    }

    @RequestMapping(value = "/get")
    @ResponseBody
    public WxUser getById(WxUser wxUser) {
        WxUser wxUser1 = wxUserService.get(wxUser);
        return wxUser;
    }

    @RequestMapping(value = "/list")
    public String list(WxUser wxUser) {
        return "shop/user/user_list";
    }

    @RequestMapping(value = "/info")
    @ResponseBody
    public List<WxUser> info(WxUser wxUser) {
        return wxUserService.findList(wxUser);
    }


    @RequestMapping(value = "/findPage")
    @ResponseBody
    public PageInfo<WxUser> findPage(WxUser wxUser) {
        return wxUserService.findPage(wxUser);
    }

    @RequestMapping(value = "/save")
    @ResponseBody
    public Result save(WxUser wxUser) {
        wxUserService.save(wxUser);
        return Result.success("保存成功");
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@RequestParam("id") String id) {
        wxUserService.logicalDeletion(id);
        return Result.success();
    }

}